<?php
ob_start();
	include('connect/connect.php');
	check_admin();
	
	if(isset($_GET['id']) && $_GET['id']!='') {
		$gvid = $_GET['id'];
		$sql = "SELECT * FROM tbl_giangvien WHERE id = '$gvid'";
		$query = mysql_query($sql) or die(mysql_error());
		$data = mysql_fetch_array($query);

	}
	
	// If record has old data type of CaRanh => show textbox, else show checkboard
	$oldCar = false;
	if ($data['f_car'] != "")
		$oldCar = true;
	
		$sql2 = "SELECT * FROM tbl_lichranhgv WHERE gvid = '$gvid'";
		$query2 = mysql_query($sql2) or die(mysql_error());
		$cargv = Array();
		while($rows = mysql_fetch_array($query2)) 
		{
			$cargv[] = $rows['carid'];
			
		}	
		
		$checkBoxes = "";
		for ($i=1; $i<4; $i++) {
			$checkBoxes .= "<tr><td align=\"center\">Ca ".$i."</td>";
			$k = ($i-1)*7;
			for ($j=$k+1; $j<=$i*7; $j++) {
				$checked = "";
				if(in_array($j, $cargv))
					$checked = "checked";
				$checkBoxes .= "<td align=\"center\"><input type=\"checkbox\" name=\"f_car[]\" value=\"".$j."\" ".$checked." /></td>";
			}
			$checkBoxes .= "</tr>";
		}
	
	$main = file_get_contents('template/main.html');
	$main = str_replace('{header}','Banner',$main);
	$main = str_replace('{body}','',$main);
	echo $main;	
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<link href="Calendar/CalendarControl.css"
      rel="stylesheet" type="text/css">

<link href="css/khiet.css" rel="stylesheet" type="text/css" />

<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
</head>
<body>
<form method="POST" action="edit_giangvien_action.php">
<input type="hidden" name="f_id" value="<?php echo $data['id']; ?>" />
Họ và tên <input type="text" name="f_hovaten" id="hovaten" value="<?php echo $data['f_hovaten']; ?>"><p>
Giới tính <select size="1" name="f_gioitinh">
			<?php
				$nam = $nu = "";
				if($data['f_gioitinh'] == 1)
					$nam = "selected";
				else
					$nu = "selected";
				echo "<option value=\"1\" $nam>Nam</option>";
				echo "<option value=\"2\" $nu>Nữ</option>";
			?>
		  </select><p>
Tuổi <input type="text" name="f_tuoi" value="<?php echo $data['f_tuoi']; ?>"><p>
Địa chỉ <input type="text" name="f_diachi" value="<?php echo $data['f_diachi']; ?>"><p>
Ca rảnh
<!-- added by thinhnc 2013-04-07 -->
<?php if($oldCar) { ?>
<input type="text" name="f_oldcar" value="<?php echo $data['f_car']; ?>" /><br />
<?php } else { ?>
<input type="hidden" name="f_oldcar" value="" />
<?php } ?>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="60px"  align="center"></td>
<td width="60px"  align="center">Thứ hai</td>
<td width="60px"  align="center">Thứ ba</td>
<td width="60px"  align="center">Thứ tư</td>
<td width="60px"  align="center">Thứ năm</td>
<td width="60px"  align="center">Thứ sáu</td>
<td width="60px"  align="center">Thứ bảy</td>
<td width="60px"  align="center">Chủ nhật</td>
</tr>
<?php 
echo $checkBoxes; ?>
</table>
<!-- end thinhnc-->
Chuyên loại hình <input type="text" name="f_chuyenloaihinh" value="<?php echo $data['f_chuyenloaihinh']; ?>"><p>
Phần mềm sử dụng <input type="Text" name="f_phanmemsudung" value="<?php echo $data['f_phanmemsudung']; ?>"><p>
Mail <input type="text" name="mail" value="<?php echo $data['mail']; ?>"><p>
SĐT <input type="Text" name="sdt" value="<?php echo $data['sdt']; ?>"><p>
<input type="submit" action="#" value="Cập nhật dữ liệu" />
<input type="reset" action="#" value="Trở lại" onclick="history.back(-1);" />
</form>
</body>
</html>